using System;
using System.Collections.Generic;

namespace Elephant.Framework
{
    /// <summary>
    /// Represents a collection of enabled states for every component in an entity.
    /// </summary>
    /// <remarks>
    /// This is useful for the scenario where you wish to disable an entity (ie. set every contained component to enabled=false),
    /// but still be able to go back to its previous state. Without keeping track of the previous state, it would be impossible
    /// to know whether a component was disabled/enabled previously.
    /// </remarks>
    internal sealed class EnabledState
    {
        Dictionary<EntityComponent, bool> state = new Dictionary<EntityComponent, bool>(); // component, enabled

        public EnabledState(IEnumerable<EntityComponent> components)
        {
            foreach (EntityComponent component in components) {
                state.Add(component, component.Enabled);
            }
        }

        /// <param name="component">The component to get enabled/disabled state of.</param>
        public bool this[EntityComponent component]
        {
            get
            {
                return state[component];
            }
        }
    }
}
